home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / usleep.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  902b  |  50 lines

  1. /*
  2.  
  3.     Emulation of BSD usleep() for Solaris 2.x
  4.  
  5.     Contributed by Hans Werner Strube
  6.  
  7. */
  8.  
  9. #include "speakfree.h"
  10. #include <sys/signal.h>
  11.  
  12. #ifndef OLDCC
  13. volatile
  14. #endif
  15. static int waiting;
  16.  
  17. static void getalrm(i)
  18.   int i;
  19. {
  20.     waiting = 0;
  21. }
  22.  
  23. void sf_usleep(t)
  24.   unsigned t;
  25. {
  26.     static struct itimerval it, ot;
  27.     void (*oldsig)();
  28.     long nt;
  29.  
  30.     it.it_value.tv_sec = t / 1000000;
  31.     it.it_value.tv_usec = t % 1000000;
  32.     oldsig = signalFUNCreturn signal(SIGALRM, getalrm);
  33.     waiting = 1;
  34.     if (setitimer(ITIMER_REAL, &it, &ot))
  35.     return /*error*/;
  36.     while (waiting) {
  37.     pause();
  38.     }
  39.     signal(SIGALRM, oldsig);
  40.     nt = ((ot.it_value.tv_sec * 1000000L) + ot.it_value.tv_usec) - t;
  41. /*printf("NT = %d\n", nt);*/
  42.     if (nt <= 0) {
  43.     kill(getpid(), SIGALRM);
  44.     } else {
  45.     ot.it_value.tv_sec = nt / 1000000;
  46.     ot.it_value.tv_usec = nt % 1000000;
  47.     setitimer(ITIMER_REAL, &ot, 0);
  48.     }
  49. }
  50.